home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Port Scanners / NX.EXE / ID_80_.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-15  |  2.3 KB  |  90 lines

  1. //
  2. // This is a sample plugin dll for nx - network explorer
  3. // This plugin returns the http server's name
  4. // Currently plugins run multithreaded
  5. // To include a plugin in an nx run add use the option -plug
  6. // And look at the plugins.txt file 
  7. //
  8. // The input to this function is Sock *s
  9. // You can get at the servername, port, etc through it
  10. //
  11. // How do you output stuff to the user?
  12. // Fill in s->szBuf with a null terminated string
  13. // Make SURE s->szBuf is null terminated before you return
  14. // We do not print here because 255 plugins all trying to 
  15. // print at the same time is not cool.
  16. // When this function returns, nx prints whatever was in s->szBuf
  17. //
  18. // mikejanzen@hotmail.com
  19. //
  20.  
  21. #define WIN32_LEAN_AND_MEAN        // Exclude rarely-used stuff from Windows headers
  22.  
  23. #include <windows.h>
  24. #include <stdio.h>
  25. #include <winsock2.h>
  26. #include <time.h>
  27.  
  28. #include "sock.h"
  29.  
  30. BOOL APIENTRY DllMain( HANDLE hModule, 
  31.                        DWORD  ul_reason_for_call, 
  32.                        LPVOID lpReserved
  33.                      )
  34. {
  35.  
  36.     switch (ul_reason_for_call)
  37.     {
  38.         case DLL_PROCESS_ATTACH:
  39.         case DLL_THREAD_ATTACH:
  40.         case DLL_THREAD_DETACH:
  41.         case DLL_PROCESS_DETACH:
  42.             break;
  43.     }
  44.     return TRUE;
  45. }
  46.  
  47.  
  48. extern "C" __declspec(dllexport) int DoSocket(Sock *s)
  49. {
  50.     unsigned long ioctlarg=0; // used to set socket to nonblocking
  51.     char outputbuf[256],*p,*p2;
  52.     int len;
  53.  
  54.     
  55.  
  56.     //
  57.     // need to set the socket to blocking !!
  58.     // you will almost always want to include this
  59.     // if you dont know what it does, just leave it in
  60.     //
  61.     ioctlsocket(s->m_Sock,FIONBIO,&ioctlarg);
  62.  
  63.     const char inputbuf[]="HEAD / HTTP/1.0\n\n";
  64.     if( send(s->m_Sock,inputbuf,strlen(inputbuf),0) == SOCKET_ERROR ) 
  65.         return WSAGetLastError();
  66.  
  67.     if( (len = recv(s->m_Sock,outputbuf,sizeof(outputbuf)-1,0)) == SOCKET_ERROR )
  68.         return WSAGetLastError();
  69.  
  70.     // find the server string
  71.     outputbuf[len]=0;  // null terminate the buffer
  72.  
  73.     // do some crappy bounds checking -- this code should be better
  74.     // but its good enough for a sample
  75.     if(strlen(outputbuf) < sizeof(s->m_szBuf)){
  76.         if( (p=strstr(outputbuf,"Server: ")) && (p2=strstr(p,"\n")) ){
  77.             p=p+8;
  78.             *p2=0;
  79.             sprintf(s->m_szBuf,"HTTP Server %s",p);
  80.             return 0;
  81.         } 
  82.         else
  83.         {
  84.             sprintf(s->m_szBuf,"HTTP Info %s",outputbuf);
  85.             sprintf(s->m_szBuf,"HTTP Server %s",p);
  86.         }
  87.     }
  88.     return 0;
  89. }
  90.